home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / main.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  13.6 KB  |  492 lines

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5.  
  6. #ifndef _dynobj_h
  7. #    include "dynobj.h"
  8. #endif
  9. #ifndef _object_h
  10. #    include "object.h"
  11. #endif
  12.  
  13. #ifndef _graph_h
  14. #    include "graph.h"
  15. #endif
  16. #ifndef _mover_h
  17. #    include "mover.h"
  18. #endif
  19.  
  20. #ifndef _game_h
  21. #    include "game.h"
  22. #endif
  23. #ifndef _snooker_h
  24. #    include "snooker.h"
  25. #endif
  26. #ifndef _cannon_h
  27. #    include "cannon.h"
  28. #endif
  29. #ifndef _pool8_h
  30. #    include "pool8.h"
  31. #endif
  32. #ifndef _carrom_h
  33. #    include "carrom.h"
  34. #endif
  35. #ifndef _hockey_h
  36. #    include "hockey.h"
  37. #endif
  38. #ifndef _curling_h
  39. #    include "curling.h"
  40. #endif
  41. #ifndef _pball_h
  42. #    include "pball.h"
  43. #endif
  44.  
  45. //
  46. // Stackgr÷▀e in Turbo-C
  47. //
  48. #ifdef __TURBOC__
  49. // #    include <dos.h>
  50. unsigned _stklen = 24000;
  51. #endif
  52.  
  53.  
  54. #ifdef DEBUG
  55. #    ifdef __TURBOC__
  56.         long debug = TCTrace;            // globale Variable
  57. #    else
  58.         long debug = UnixTrace;
  59. #    endif
  60. #endif
  61.  
  62. #ifdef __TURBOC__
  63. void start_log( const char * /* name */ )    {}
  64. void end_log() {}
  65. #else
  66. void start_log( const char *name );
  67. void end_log();
  68.  
  69. #endif
  70.  
  71. double current_time;
  72.  
  73. int    deluxe =   0;                        // Luxus-Ausfⁿhrung bei Pool-Billard
  74.                                     //         half full
  75.                                                 // case 1:  4    0   Intro
  76.                                                 // case 2:  4    3   game
  77.                                                 // case 3:  2    1   old game
  78. int    size                = 800;            // Default-Gr÷▀e
  79. int    sound_request    = 0;                // Wunsch nach Sound
  80. int    light_flag        = 1;                // Light-Source
  81. int    color_flag        = 0;                // Desired table color
  82. int    nohint_flag        = 0;                // Dont draw arrows for hints
  83.  
  84. #ifdef GERMAN
  85.  
  86. void usage() {
  87.     printf("usage: flying <options>\n" );
  88.     printf("options:\n" );
  89.  
  90.     printf("       -snooker      Snooker          (xsnooker)\n" );
  91.     printf("       -pool         Pool-Billard     (xpool)\n" );
  92.     printf("       -cannon       Karambolage      (xcannon)\n" );
  93.     printf("       -carrom       Carrom           (xcarrom)\n" );
  94.     printf("       -hockey       Air-Hockey       (xhockey)\n" );
  95.     printf("       -curling      Eisstockschie▀en (xcurling)\n" );
  96. //    printf("       -bowling      Bowling\n" );
  97. //    printf("       -golf         Minigolf\n" );
  98.     printf("       -ft <n>       Gr÷▀e des Pool-Tisches in Fu▀ [6...9]\n" );
  99.     printf("       -deluxe       Luxus-Ausfⁿhrung Pool-Billard\n" );
  100. //    printf("       -light <n>    ─nderung der Beleuchtung\n" );
  101.     printf("       -[red|green|blue] Tischfarbe\n" );
  102.     printf("       -nohints      Abschalten der Hilfspfeile\n" );
  103.     printf("       -demo         Start des Demo-Modes\n" );
  104.     printf("       -presets      Ausgabe der Konfidaten\n" );
  105. #ifndef __TURBOC__
  106.     printf("       -size <n>     Breite des X-Fensters\n" );
  107.     printf("       -root         Maximalgr÷▀e im Hintergrund (default)\n" );
  108.     printf("       -display      Ausgabedisplay (Default: Inhalt von $DISPLAY)\n" );
  109.     printf("       -in1          Display fⁿr erste Maus (Default: wie -display)\n" );
  110.     printf("       -in2          Display fⁿr zweite Maus\n" );
  111. #endif
  112. #if (SOUND_SUBSYSTEM)
  113.     printf("       -sound        Tonausgabe\n" );
  114. #endif
  115.     printf("       -time <n>     Geschwindigkeitsmessung fⁿr <n> Sekunden Berechnungszeit\n");
  116.     printf("       -maxspeed     keine Zwischenschritte (nicht zeitsynchron)\n" );
  117.  
  118. #ifdef DEBUG
  119.     printf("       -debug <n>    Debug-Information nach stdout\n" );
  120.     printf("\nDebug-Flags:\n");
  121.     show_flags();
  122. #endif
  123.     exit(-1);
  124. }
  125.  
  126. #else
  127.  
  128. void usage() {
  129.     printf("usage: flying <options>\n" );
  130.     printf("options:\n" );
  131.     printf("    select game:\n" );
  132.     printf("       -snooker      Snooker      (xsnooker)\n" );
  133.     printf("       -pool         Pool-Billard (xpool)\n" );
  134.     printf("       -cannon       Karambolage  (xcannon)\n" );
  135.     printf("       -carrom       Carrom       (xcarrom)\n" );
  136.     printf("       -hockey       Air-Hockey   (xhockey)\n" );
  137.     printf("       -curling      Curling      (xcurling)\n" );
  138. //    printf("       -bowling      Bowling\n" );
  139. //    printf("       -golf         Miniature-Golf\n" );
  140.     printf("       -ft <n>       table size in feet [6...9]\n" );
  141.     printf("       -deluxe       special version of pool\n" );
  142. //    printf("       -light <n>    0 - static, 1 moving light\n" );
  143.     printf("       -[red|green|blue] select billard table color\n" );
  144.     printf("       -nohints      turn off hint arrows\n" );
  145.     printf("       -demo         demonstration (no pockets)\n" );
  146.     printf("       -presets      show preset variables\n" );
  147. #ifndef __TURBOC__
  148.     printf("    X11 options:\n");
  149.     printf("       -size <n>     window size\n" );
  150.     printf("       -root         full screen (default)\n" );
  151.     printf("       -display      ouput-display (def: $DISPLAY)\n" );
  152.     printf("       -in1          input-display (def: = output-display)\n" );
  153.     printf("       -in2          alternate input-display\n" );
  154. #endif
  155. #if (SOUND_SUBSYSTEM)
  156.     printf("       -sound        clicks when hitting balls\n" );
  157. #endif
  158.     printf("    for time measurements:\n");
  159.     printf("       -time <n>     stop after n seconds\n");
  160.     printf("       -maxspeed     jump from collision to collision (asynchronous)\n" );
  161.  
  162. #ifdef DEBUG
  163.     printf("    for debugging:\n");
  164.     printf("       -debug <n>    verbose messages at stdout\n" );
  165.     printf("\ndebug-flags:\n");
  166.     show_flags();
  167. #endif
  168.  
  169.  
  170.     printf("\nsmail (for gifts):\n");
  171.     printf("        Helmut Hoenig\n");
  172.     printf("        Hopfenstrasse 8a\n");
  173.     printf("        65520 Bad Camberg\n");
  174.     printf("        GERMANY\n");
  175.     printf("\n");
  176.     printf( "                By the way, I am collecting banknotes!!\n");
  177.     printf( "    If you want to join into my collection, get any bill of your country,\n");
  178.     printf( " sign it on the backside and send it to me so I will pin it on my world map.\n");
  179.     printf( "             (Don't forget the exact location for the pin :-)\n\n");
  180.     exit(-1);
  181. }
  182.  
  183. #endif
  184.  
  185. int main(int argc, char **argv)
  186. {
  187. char        *disp=0l;    // Ausgabe
  188. char        *in1=0l;        // Eingabe1
  189. char        *in2=0l;        // Eingabe2
  190. double    stop_time=0.0;
  191. long        all_cycles=0l;
  192. int        max_speed    = 0;
  193. double    ft = 0.0;
  194.  
  195.             size = ON_ROOT;
  196. int            game_flag  = 0;
  197. PBallType    game_pball = BillardQueue;
  198. int        demo_flag  = 0;
  199. double    demo_param = 0.0;
  200. char        pressed_key=0;
  201.  
  202.     srand( (unsigned)GetCurrentTime() );
  203.     load_konfi();
  204.  
  205.     if (!strcmp(argv[0],"xsnooker"))                    game_flag = 1;
  206.     else if (!strcmp(argv[0],"xpool"))                game_flag = 2;
  207.     else if (!strcmp(argv[0],"xcannon"))            game_flag = 3;
  208.     else if (!strcmp(argv[0],"xcarrom"))            game_flag = 4;
  209.     else if (!strcmp(argv[0],"xhockey"))            game_flag = 5;
  210.     else if (!strcmp(argv[0],"xcurling"))            game_flag = 6;
  211.     else if (!strcmp(argv[0],"xbowling"))            game_flag = 7;
  212.     else if (!strcmp(argv[0],"xgolf"))                game_flag = 8;
  213.  
  214.     for (int i=1; i<argc; i++ ) {
  215.         if (!strcmp(argv[i],"-snooker"))                game_flag = 1;
  216.         else if (!strcmp(argv[i],"-pool"))            game_flag = 2;
  217.         else if (!strcmp(argv[i],"-cannon"))        game_flag = 3;
  218.         else if (!strcmp(argv[i],"-carrom"))        game_flag = 4;
  219.         else if (!strcmp(argv[i],"-hockey"))        game_flag = 5;
  220.         else if (!strcmp(argv[i],"-curling"))        game_flag = 6;
  221.         else if (!strcmp(argv[i],"-bowling"))        game_flag = 7;
  222.         else if (!strcmp(argv[i],"-golf"))            game_flag = 8;
  223.         else if (!strcmp(argv[i],"-deluxe")) {
  224.                     deluxe    = (i<argc-1)?atoi(argv[i+1]):0;
  225.                     if (deluxe) { i++; } else { deluxe = 2; }
  226.                     game_flag =   2;
  227.                     if (!ft)        ft = 8.0;
  228.         }
  229.         else if (!strcmp(argv[i],"-light")) {
  230.                     light_flag = atoi(argv[++i]);
  231.         }
  232.         else if (!strcmp(argv[i],"-red"))            color_flag = 1;
  233.         else if (!strcmp(argv[i],"-green"))            color_flag = 2;
  234.         else if (!strcmp(argv[i],"-blue"))            color_flag = 3;
  235.         else if (!strcmp(argv[i],"-nohints"))        nohint_flag = 1;
  236.         else if (!strcmp(argv[i],"-demo"))            {
  237.                 demo_flag=1;
  238.                 if (i<argc-1)            demo_param = atof(argv[i+1]);    // read param
  239.                 else                        demo_param = 0.0;                    // no param
  240.                 if (demo_param>0.0)     i++;                                    // skip arg
  241.         }
  242. #if (SOUND_SUBSYSTEM)
  243.         else if (!strcmp(argv[i],"-sound"))            sound_request = 1;
  244. #endif
  245.         else if (!strcmp(argv[i],"-time"))            stop_time = atof(argv[++i]);
  246.         else if (!strcmp(argv[i],"-size"))            size = atoi(argv[++i]);
  247.         else if (!strcmp(argv[i],"-ft"))                ft = atof(argv[++i]);
  248.         else if (!strcmp(argv[i],"-display"))        disp = argv[++i];
  249.         else if (!strcmp(argv[i],"-in1"))            in1 = argv[++i];
  250.         else if (!strcmp(argv[i],"-in2"))            in2 = argv[++i];
  251.         else if (!strcmp(argv[i],"-root"))            size = ON_ROOT;
  252.         else if (!strcmp(argv[i],"-maxspeed")) {
  253.                 if (!stop_time)        stop_time = 5.0;
  254.                 max_speed = 1;
  255.                 demo_flag = 1;
  256.         }
  257.         else if (!strcmp(argv[i],"-presets"))    {    show_defaults();    exit(0);    }
  258.  
  259. #ifdef DEBUG
  260.         else if (!strcmp(argv[i],"-debug"))            debug= atoi(argv[++i]);
  261.         else if (!set_debug(argv[i]))                    ;
  262. #endif
  263.         else if (argv[i][0]=='-')                        usage();
  264.         else usage();
  265.     }
  266.  
  267. #ifdef DEBUG
  268.     if (debug&Intro) {
  269.         debug |= __ShowAll | ForceCalc;
  270.         size            = 600;
  271.         deluxe        = 1;
  272.         game_flag    =   2;
  273.         ft                = 8.0;
  274.     }
  275.     if ((size==ON_ROOT)&&
  276.         ( debug&ShowColors||debug&ShowLight||debug&ShowRings||debug&ShowTurns
  277.         ||debug&GameState))
  278.     {
  279.         size            = 600;
  280.     }
  281.     if (debug&xdb) {
  282.         size            = 600;
  283.         in1            = "hgr49:0.0";
  284.     }
  285. #endif
  286.  
  287. do {
  288.     PBall    *p1=0;
  289.     PBall    *p2=0;
  290.     InitColors();
  291.  
  292. #ifdef DEBUG
  293.     if (debug&Motion) {
  294.         ft = 8.0;
  295.         game_flag = 2;
  296.         deluxe    = 2;
  297.         g=(Game*) new Pool8Test(ft,demo_param);
  298.     }
  299.     else
  300. #endif
  301.     switch(game_flag) {
  302.     case 1:        if (demo_flag) {
  303.                         if (demo_param)    g=(Game*) new SnookerDemo(demo_param);
  304.                         else                    g=(Game*) new SnookerDemo();
  305.                         break;
  306.                     }
  307.                     g = (Game*)new Snooker;
  308.                     start_log( "Snooker" );
  309.                     break;
  310.     case 2:
  311. #ifdef DEBUG
  312.                     if ((ft<1||ft>9))        ft = 6.0 + (rand()%30) / 10;
  313. #else
  314.                     if ((ft<6||ft>9))        ft = 6.0 + (rand()%30) / 10;
  315. #endif
  316.                     if (demo_flag) {
  317.                         if (demo_param)    g=(Game*) new Pool8Demo(ft,demo_param);
  318.                         else                    g=(Game*) new Pool8Demo(ft);
  319.                         break;
  320.                     }
  321.                     g = (Game*)new Pool8(ft);
  322.                     start_log( "8-Ball" );
  323.                     break;
  324.     case 3:        g = (Game*)new Cannon;
  325.                     start_log( "Cannon" );
  326.                     break;
  327.     case 4:        if (demo_flag) {
  328.                         if (demo_param)    g=(Game*) new CarromDemo(demo_param);
  329.                         else                    g=(Game*) new CarromDemo();
  330.                         break;
  331.                     }
  332.                     g = (Game*)new Carrom;
  333.                     start_log( "Carrom" );
  334.                     break;
  335.     case 5:        if (demo_flag) {
  336.                         if (demo_param)    g=(Game*) new TestHockey(demo_param);
  337.                         else                    g=(Game*) new TestHockey();
  338.                         break;
  339.                     }
  340.                     g = (Game*)new Hockey;
  341.                     start_log( "Hockey" );
  342.                     break;
  343.     case 6:        g = (Game*)new Curling;
  344.                     start_log( "Curling" );
  345.                     break;
  346.     default:        if (demo_flag) {
  347.                         if (demo_param)    g=(Game*) new CarromDemo(demo_param);
  348.                         else                    g=(Game*) new CarromDemo();
  349.                         break;
  350.                     }
  351.                     usage();                        break;
  352.     };
  353.  
  354. //
  355. // Durch das Instanziieren der Game-Klasse entstanden Farbanfordungen
  356. // welche nun befriedigt werden mⁿssen, bevor sie in den InitPlayground
  357. // Routinen verwendet werden k÷nnen.
  358.     AllocColors();
  359. //
  360. // Die fⁿr die einzelnen Spiele notwendigen Objekte werden nun angelegt.
  361.     g->InitPlayground();
  362.     MapMainWindow();
  363.  
  364.     switch(game_flag) {
  365.     case 5:    game_pball = DiscSlider;     break;
  366.     case 6:    game_pball = DiscThrower;    break;
  367.     default:    game_pball = BillardQueue;    break;
  368.     }
  369.  
  370.     if (in1)     p1 = new PBall( game_pball, in1 );
  371.     if (in2)        p2 = new PBall( game_pball, in2 );
  372.     if (!p1)        p1 = new PBall( game_pball, (disp)?disp:"" );
  373.  
  374.  
  375.     g->DrawBackground();
  376.     DynObj::DynInitAll();
  377. #ifdef DEBUG
  378.     if (debug&ObjectInfo)    Object::ForAll(&Object::Info);
  379. #endif
  380.     current_time = GetCurrentTime();
  381.     DynObj::ForAllDyn(&DynObj::Reset);
  382.     DynObj::ForAllDyn(&DynObj::Redraw);
  383.     current_time = GetCurrentTime();
  384.     DynObj::ForAllDyn(&DynObj::CollisionCalc);
  385.     if (stop_time)        stop_time+=current_time;        // Jetzt geht's los ...
  386.  
  387.  
  388.     while(1) {
  389.         double    collision_step;
  390.         collision_step = DynObj::CollisionAll();    // nΣchste Kollisionszeit
  391.  
  392.         double    current_step   = GetCurrentTime()-current_time;
  393.  
  394.         if ((!max_speed)&&collision_step>current_step) {
  395.             // Zwischenschritt einlegen
  396. #ifdef DEBUG
  397.             if (debug&MoveAll) {
  398.                     printf("MOVE intermediate: +%f = %f (OFF: %f, Collide: %f)\n",
  399.                                 current_step, current_time+current_step,
  400.                                 0.0,
  401.                                 (collision_step!=MAX_TIME)?collision_step:-1 );
  402.             }
  403. #endif
  404.             current_time += current_step;
  405.             DynObj::ForAllDyn(&DynObj::Move,current_step);
  406.         }
  407.         else {
  408.             // Kollisionsschritt einlegen
  409. #ifdef DEBUG
  410.             if (debug&MoveAll) {
  411.                     printf("MOVE to collision: +%f = %f (OFF: %f)\n",
  412.                                 collision_step, current_time+collision_step,
  413.                                 current_step-collision_step );
  414.             }
  415. #endif
  416.             current_time+=collision_step;
  417.             DynObj::ForAllDyn(&DynObj::Move,collision_step);
  418.             DynObj::Collide();                            // Kollision ausfⁿhren
  419.  
  420. #if (0)
  421. #ifdef STATISTICS
  422. {
  423. static double next_offrun=0;
  424.  
  425.             if (next_offrun<current_time)
  426.             {
  427.                 char    buffer[30];
  428.                 if (current_step-collision_step>=0.05)
  429.                         sprintf( buffer, "Offset:%6.1fs", current_step-collision_step );
  430.                 else    buffer[0] = '\0';
  431.                 showinfo(OffsetInfo,buffer);
  432.                 next_offrun = current_time+0.50;
  433.             }
  434. }
  435. #endif
  436. #endif
  437.         }
  438.  
  439. #ifdef STATISTICS
  440. {
  441. static double next_rate        = 0.0;
  442. static double cycle_start    = 0.0;
  443. static int off                    = 0;
  444. static int cycle_count        = 0;
  445.  
  446.         double check_time = GetCurrentTime();
  447.         cycle_count++;
  448.         if (next_rate<check_time)
  449.         {  char    buffer[30];
  450.             double            time_step = check_time - cycle_start;
  451.  
  452.             sprintf( buffer, "Rate:%7.1f/s", cycle_count/time_step );
  453.             showinfo( CycleRate, buffer );
  454.             cycle_count=0;
  455.             sprintf( buffer, "Moves:%7.1f/s", BallMover::moves/time_step );
  456.             showinfo( MoveRate, buffer );
  457.             BallMover::moves=0;
  458.  
  459.             if (check_time-current_time>0.05) {
  460.                 sprintf( buffer, "Offset:%7.1f/s", check_time-current_time );
  461.                 showinfo(OffsetInfo,buffer);
  462.                 off=1;
  463.             }
  464.             else if (off) {
  465.                 showinfo(OffsetInfo,"");
  466.                 off=0;
  467.             }
  468.             cycle_start=check_time;
  469.             next_rate  =check_time+0.50;
  470.         }
  471. }
  472. #endif
  473.         PBallTop::ForAll(&PBallTop::Update);
  474.         all_cycles++;
  475.         pressed_key = GetKey();
  476.         if (pressed_key=='q'||pressed_key=='r'||((stop_time)&&(GetCurrentTime()>stop_time)))        break;
  477.     };
  478.  
  479.     if (p2)        delete p2;
  480.     if (p1)        delete p1;
  481.     delete g;
  482.     CloseGraphic();
  483.     printf( "end after %ld cycles\n", all_cycles );
  484.     Object::ForAll(&Object::Info);
  485. }
  486. while( pressed_key=='r' );
  487.  
  488.     end_log();
  489.     return 0;
  490. }
  491.  
  492.